157B - Trace - CodeForces Solution


geometry sortings *1000

Please click on ads to support us..

Python Code:

import math
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
ans=0

for i in range(n):
    ans += (lst[i] * lst[i] * (1 - i%2 * 2))
    
z = round(math.asin(1) * 2 * ans, 10)

if z<0:
    print(z*-1)
else:
    print(z)

C++ Code:

#include <bits/stdc++.h>
using namespace std;


int main()
{
    int n;
    cin>>n;
    
    int a[n+1] ={0};
    
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    double sum = 0;
    
    
    for (int i = 0; i <=n; i+=2)
    {
        if(a[i] == 0 )
        {
            break;
        }
        sum+=(a[i]*a[i]-a[i+1]*a[i+1]);
    }
    //cout<<sum<<endl;
    cout<<(3.1415926536*sum)<<endl;
    

    
}


Comments

Submit
0 Comments
More Questions

1149A - Prefix Sum Primes
277A - Learning Languages
769A - Year of University Entrance
1738A - Glory Addicts
1738C - Even Number Addicts
1064B - Equations of Mathematical Magic
384A - Coder
1738B - Prefix Sum Addicts
1352D - Alice Bob and Candies
1316D - Nash Matrix
1548B - Integers Have Friends
348A - Mafia
315B - Sereja and Array
204A - Little Elephant and Interval
385B - Bear and Strings
114C - Grammar Lessons
1427A - Avoiding Zero
583A - Asphalting Roads
1358B - Maria Breaks the Self-isolation
828A - Restaurant Tables
1735A - Working Week
1735D - Meta-set
1735B - Tea with Tangerines
1735C - Phase Shift
1321C - Remove Adjacent
281B - Nearest Fraction
1043A - Elections
1598C - Delete Two Elements
1400C - Binary String Reconstruction
1734D - Slime Escape